Repository navigation
fix(signature): return False for malformed timestamp, signature or body in SignatureVerifier.is_valid - #2075
Open
tony1233200 wants to merge 1 commit into
Conversation
…dy in SignatureVerifier.is_valid Fixes slackapi#2067: is_valid() raised instead of returning False for malformed inputs that arrive straight from request headers / body: - non-numeric timestamp ("abc") raised ValueError from int(timestamp) - non-ASCII signature ("v0=é") raised TypeError from hmac.compare_digest - non-UTF-8 bytes body raised UnicodeDecodeError from body.decode("utf-8") Each case now returns False, matching the existing contract for missing values (test_is_valid_none). Valid signatures still return True. Adds regression tests covering all three cases via is_valid() and is_valid_request().
|
Thanks for the contribution! Before we can merge this, we need @yc25778-droid to sign the Salesforce Inc. Contributor License Agreement. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2067.
SignatureVerifier.is_valid()(andis_valid_request()) returnedFalsefor missing values but raised for three kinds of malformed input that arrive straight from theX-Slack-Request-Timestamp/X-Slack-Signatureheaders and the request body, so in bolt-python such a request ended as a 500 instead of the 401invalid requestresponse:"abc") →ValueErrorfromint(timestamp)"v0=é") →TypeErrorfromhmac.compare_digest, which only accepts ASCII stringsb"\xff\xfe") →UnicodeDecodeErrorfrombody.decode("utf-8")ingenerate_signatureFix: in
is_valid(), each case now returnsFalse— the non-numeric timestamp is caught aroundint(), a non-ASCII signature is rejected beforecompare_digest(), and aUnicodeDecodeErrorfromgenerate_signature()is caught. No blankettry/except: the guards are scoped to the exact failing operations, and a valid signature still returnsTrue.Note: open PR #1968 already fixes the timestamp case only (no reference to #2067). This PR covers all three cases from #2067; if #1968 lands first, the timestamp hunk here becomes redundant.
Testing
New regression tests in
tests/slack_sdk/signature/test_signature_verifier.py(test_is_valid_malformed_timestamp,test_is_valid_malformed_signature,test_is_valid_malformed_body,test_is_valid_request_malformed_inputs):is_validandis_valid_request);repro_2067.pyshows the same three raises.pytest tests/slack_sdk/signature/test_signature_verifier.py— 16 passed (12 existing + 4 new);repro_2067.py— all 9 checks pass, including valid signature stillTrueand missing values stillFalse.Other checks:
ruff format --check slack_sdk/signature/__init__.py tests/slack_sdk/signature/test_signature_verifier.pyandruff check slack_sdk/signature/pass../scripts/run_validation.shwas not run in full (it installs dependencies and runs the whole suite); the signature test file and the lint checks above were run instead.Category
tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.